<template>
  <div id="ZoneDetails">
    <v-detail :detailData="inputData"
              :inputConfig="inputConfig"
              :rules="rules"
              @pop="setData"
              ref="input"></v-detail>
  </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "ZoneDetails",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object
    }
  },
  data () {
    //自定义验证规则
    const putawayzoneValidate = (rule, value, callback) => {
      let reg = /^[a-z_A-Z0-9-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'<>~\·`\?:;|]+$/;//匹配字母、数字及所有英文符号的正则表达式
      if (!reg.test(value)) {
        this.$message.error(this.$t('msg.msg18'));
        this.inputData.putawayzone = ''
        callback(new Error())
      } else {
        callback()
      }
    }


    //自定义验证规则,验证LPN是否合法
    const maxpalletsperskuValidate = (rule, value, callback) => {
      let reg = /^\+?[1-9]\d*$/;//大于零的正整数
      if (!reg.test(value)) {
        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
        this.inputData.maxpalletspersku = 0
        callback(new Error())
      } else {
        callback()
      }
    }


    //自定义验证规则
    const picktolocValidate = (rule, value, callback) => {
      if (value != '') {
        this.$api.get(`/queryLocByLocKey/${value}`).then(res => {
          
            if (!res.bean) {
              this.$message.error(this.$t('msg.msg7'));
              callback(new Error());
            } else {
              callback()
            }

          
        })

      } else {
        callback()
      }
    }
    return {
      inputConfig: [
        [
          {
            type: "input",
            label: this.$t('config.area'),
            props: "putawayzone",
            disabled: !this.$parent.newFlag
          },
          {
            type: "input",
            label: this.$t('common.desc'),
            props: "descr",
          },
          {
            type: "select",
            label: this.$t('outbound.posvermethod'),
            props: "posvermethod",
            options: this.getOptions('querycodeLkup/PVTYPE')
          },
          {
            type: "select",
            label: this.$t('outbound.replenishment_Hotlevel'),
            props: "replenishment_Hotlevel",
            options: this.getOptions('querycodeLkup/TMPRIORITY')
          },
          {
            type: "input",
            label: this.$t('outbound.maxpalletspersku'),
            props: "maxpalletspersku",
          },
          {
            type: "checkbox",
            label: this.$t('outbound.replenishment_Flag'),
            props: "replenishment_Flag",
          },
        ],
        [
          {
            type: "table",
            label: this.$t('outbound.picktoloc'),
            props: "picktoloc",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input"
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCTYPE')
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions('queryPutawayzoneDropDown')
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCFLAG')
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCCATEGRY')
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleLot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "input"
              }
            ],
            url: "/queryLoc/"
          },
          {
            type: "table",
            label: this.$t('config.interLoc'),
            props: "inloc",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input"
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCTYPE')
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions('queryPutawayzoneDropDown')
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCFLAG')
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCCATEGRY')
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleLot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "input"
              }
            ],
            url: "/queryLoc/"
          },
          {
            type: "table",
            label: this.$t('config.outLoc'),
            props: "outloc",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input"
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCTYPE')
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions('queryPutawayzoneDropDown')
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCFLAG')
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCCATEGRY')
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleLot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "input"
              }
            ],
            url: "/queryLoc/"
          },
          {
            type: "table",
            label: this.$t('config.temporaryLoc'),
            props: "abandonloc",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input"
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCTYPE')
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions('queryPutawayzoneDropDown')
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCFLAG')
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCCATEGRY')
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleLot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "input"
              }
            ],
            url: "/queryLoc/"
          },
          {
            type: "select",
            label: this.$t('config.maxCount'),
            props: "top_Off",
            options: this.getOptions('querycodeLkup/TOPOFF')
          },
          {
            type: "checkbox",
            label: this.$t('config.clearLoc'),
            props: "clean_Location",
          },
        ],
        [
          {
            type: "select",
            label: this.$t('config.pickConfirem'),
            props: "pickcc",
            options: this.getOptions('querycodeLkup/PICKCC')
          },
          {
            type: "input",
            label: this.$t('config.qtyEqualZero'),
            props: "qtycc",
          },
          {
            type: "select",
            label: this.$t('config.defaultLabelPrint'),
            props: "defaultlabelprinter",
            options: this.getOptions('queryDefaultlabelprinterDropDown')
          },
          {
            type: "select",
            label: this.$t('config.defaultreportPrint'),
            props: "defaultreportprinter",
            options: this.getOptions('queryDefaultreportprinterDropDown')
          },
          {
            type: "checkbox",
            label: this.$t('config.autoPrintLabel'),
            props: "autoprintaddrlabel",
          },
          {
            type: "checkbox",
            label: this.$t('config.autoPrintContent'),
            props: "autoprintcartoncontent",
          }
        ],
        [
          {
            type: "input",
            label: this.$t('config.floor'),
            props: "rtxfloor",
          }
        ]
      ],
      rules: {
        putawayzone: [
          { required: true, validator: putawayzoneValidate, trigger: 'blur' },
        ],
        maxpalletspersku: [
          { required: true, validator: maxpalletsperskuValidate, trigger: 'blur' },
        ],
        descr: [
          { required: true, message: this.$inputPlease("common.desc"), trigger: 'blur' },
        ],
        picktoloc: [
          { validator: picktolocValidate, trigger: 'blur' },
        ],
        inloc: [
          { validator: picktolocValidate, trigger: 'blur' },
        ],
        outloc: [
          { validator: picktolocValidate, trigger: 'blur' },
        ],
        abandonloc: [
          { validator: picktolocValidate, trigger: 'blur' },
        ],
      },
    }
  },
  methods: {
    setData (data, id, callback) {
      if (id == "0") {
        this.inputData.picktoloc = data.loc;
      } else if (id == "1") {
        this.inputData.inloc = data.loc;
      } else if (id == "2") {
        this.inputData.outloc = data.loc;
      } else if (id == "3") {
        this.inputData.abandonloc = data.loc;
      }
      callback(false);
    }
  },
  mounted () {

  },
  components: {
    "v-detail": detail
  }
}
</script>

<style scoped>
</style>
